#include <iostream>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <set>

using std::vector;
using std::deque;
using std::string;
using std::ostream;
using std::cout; 
using std::endl;
using std::set;

class Person
{
friend ostream& operator<<(ostream& os, const Person& rhs);
public:
    Person(string name, double score = 0)
        : _name(name)
        , _score(score){}
    void set_score(double score){
        _score = score;
    }
private:
    string _name;
    double _score;
};

ostream& operator<<(ostream& os, const Person& rhs){
    os << rhs._name << " " << rhs._score;
    return os;
}

// 评委打分的例子：
// 要求：有五名选手ABCDE，10个评委打分，去掉最高分和最低分，求出每个选手的平均分。
// 思路： 1.创建Person类，定义name，score成员属性；创建五名选手存放到vector容器中；
// 2.遍历vector容器，首先10个评委的打分存放到deque容器中，sort算法对分数排序，去掉最高最低分；
// 3.deque容器遍历，进行剩余分数的累加，求平均；
// 4.输出每个选手的姓名，成绩
// 提示：还是容器vector与deque的基本使用

int main()
{
    vector<Person> v = {{"张三"}, {"李四"},{"王五"},{"赵六"},{"斛珠"}};

    double i = 99.5;
    for(auto& elem : v)
    {
        double score = i;
        deque<double> Dscore;
        for(; i >= score - 4.5; i-=0.5)
        {
            Dscore.push_back(i);
        }
        std::sort(Dscore.begin(), Dscore.end());
        Dscore.pop_back();
        Dscore.pop_front();
        score = 0;
        for(auto& elem : Dscore){
            score+=elem;
        }
        elem.set_score(score/10);
    }

    for(auto& elem : v){
        cout << elem << endl;
    }


    set<Person> s;
    return 0;
}